#ifndef SELECTIONTOOL_H
#define SELECTIONTOOL_H

#include "globalstates.h"
#include "rendermanager.h"
#include "Drawing.h"
#include "vector3.h"
#include "tool.h"
#include "AABB.h"
#include <iostream>
#include <algorithm>

#define DEFAULT_DISTANCE 10

class SelectionTool : virtual public Tool
{
public:
    enum MODE {SCALE = 1, TRANSLATE = 2};
    enum ACTION {EDIT_ADD = 0, ADD = 1, SUBTRACT = 2, EDIT_SUBTRACT=3};
private:
    enum KEY_SHORTCUTS {KEY_RESET = Qt::Key_R,
                        KEY_FIX_X = Qt::Key_X,
                        KEY_FIX_Y = Qt::Key_C,
                        KEY_FIX_Z = Qt::Key_Z,
                        KEY_LEFT = Qt::Key_1,
                        KEY_RIGHT = Qt::Key_2,
                        KEY_UP = Qt::Key_3,
                        KEY_DOWN = Qt::Key_4,
                        KEY_IN = Qt::Key_6,
                        KEY_OUT = Qt::Key_5};
    enum MODIFIERS {KEY_SUBTRACT = Qt::AltModifier,
                    KEY_ADD = Qt::ShiftModifier,
                   KEY_TRANSLATE = Qt::ControlModifier};
    GlobalStates* global;
    SelectionTool();
    vector3<int> startCoords;
    vector3<int> endCoords;
    vector3<int> prevStart;
    vector3<int> prevEnd;
    vector3<int> referenceCoords;
    set<vector3<int> > prevState;
    MODE mode;
    ACTION action;
    char axesToFix;
    bool isDragging;
    bool showBox;



public:
    static SelectionTool* getInstance();
    static void addSelectionBox(int* a, int* b, int c, int& position);

    //GET, SET and TOGGLE methods
    string getType();
    bool isAxisFixed(int axis);
    void setAxis(int axis, bool toFix);
    Result setAction(ACTION a);
    Result setMode(MODE m);
    int getMode();
    int getAction();
    Result setStartCoords(vector3<int> s);
    Result setEndCoords(vector3<int> e);

    // BACKEND methods
    void execute();
    Result operationHandler(vector3<int> currentCoords);
    void modifyActiveSelection();

    //GUI methods
    void display();
    Result mouseMoveEvent(QMouseEvent *event);
    Result mousePressEvent(QMouseEvent *event);
    Result mouseReleaseEvent(QMouseEvent *event);
    Result keyPressEvent(QKeyEvent *event);
    Result keyReleaseEvent(QKeyEvent *event);

    friend class SelectionToolATD;
    friend class MagicBrushATD;

};


#endif // SELECTIONTOOL_H
